package com.spring5.testdemo;

import com.spring5.bean.Emp;
import com.spring5.service.UserService;
import org.junit.Test;
import org.junit.jupiter.api.DisplayName;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestBean {

  @Test
  public void testBean1() {
    // 1 加载spring配置文件
    ApplicationContext context = new ClassPathXmlApplicationContext("bean2.xml");

    // 2 获取配置创建的对象
    UserService userService = context.getBean("userService", UserService.class);

    userService.add();
  }

  @DisplayName("注入属性-内部bean和级联赋值")
  @Test
  public void testBean2() {
    // 1 加载spring配置文件
    ApplicationContext context = new ClassPathXmlApplicationContext("bean4.xml");

    // 2 获取配置创建的对象
    Emp emp = context.getBean("emp", Emp.class);

    emp.add();
  }
}
